﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using Utils;
using Maticsoft.DBUtility;

public partial class partner_index : FBasePage
{
    // Fields

    public string strNav = "";
    public string strpage;
    public string strWebName = "";

    // Methods
    private void initNav()
    {
        StringBuilder builder = new StringBuilder();
        string str = "";
        if ((base.Request["gid"] == null) || (base.Request["gid"].ToString() == ""))
        {
            str = "";
            builder.Append("<li class=\"current\"><a href=\"/partner/index.aspx\">所有</a><span></span></li>");
        }
        else
        {
            str = base.Request["gid"].ToString();
            builder.Append("<li ><a href=\"/partner/index.aspx\">所有</a><span></span></li>");
        }
        if ((base.ASSystem != null) && (base.ASSystem.Catepartner == 1))
        {
            DataSet list = new Maticsoft.BLL.Category().GetList(" Zone='partner' and Display='Y' order by Sort_order desc");
            if (((list != null) && (list.Tables.Count > 0)) && (list.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < list.Tables[0].Rows.Count; i++)
                {
                    DataRow row = list.Tables[0].Rows[i];
                    builder.Append("<li ");
                    if (str == row["id"].ToString())
                    {
                        builder.Append("class=\"current\" ");
                    }
                    builder.Append(" ><a href=\"/partner/index.aspx?gid=" + row["id"].ToString() + "\">" + row["Name"].ToString() + "</a><span></span></li>");
                }
            }
        }
        this.strNav = builder.ToString();
    }

    private void initPage()
    {
        StringBuilder builder = new StringBuilder();
        Maticsoft.Model.Partner partner = new Maticsoft.Model.Partner();
        string str = "";
        if ((base.Request["gid"] == null) || (base.Request["gid"].ToString() == ""))
        {
            str = "";
        }
        else
        {
            str = base.Request["gid"].ToString();
        }
        if (!Utility.IsNum(str))
        {
            this.SetError("你输入的参数有误！");
        }
        else
        {
            int num;
            string where = " 1=1 ";
            if (str != "")
            {
                where = where + " and Group_id=" + str;
            }
            if (((base.ASSystem != null) && (base.CurrentCity != null)) && (base.ASSystem.Citypartner == 1))
            {
                where = where + " and City_id=" + base.CurrentCity.Id;
            }
            DataSet set = DbHelperSQL.Page(10, this.pager.CurrentPageIndex, "Partner", where, "  Create_time desc", "*", out num);
            if (((set != null) && (set.Tables.Count > 0)) && (set.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < set.Tables[0].Rows.Count; i++)
                {
                    string str3 = set.Tables[0].Rows[i]["ID"].ToString();
                    string str4 = set.Tables[0].Rows[i]["Title"].ToString();
                    string str5 = set.Tables[0].Rows[i]["Phone"].ToString();
                    string str6 = set.Tables[0].Rows[i]["Image"].ToString();
                    string str7 = set.Tables[0].Rows[i]["Other"].ToString();
                    if (set.Tables[0].Rows[i]["Open"].ToString().ToUpper() == "Y")
                    {
                        builder.Append("<li class=\"\">");
                        builder.Append("<h4><a href=\"/partner.aspx?id=" + str3 + "\" title=\"" + str4 + "\" target=\"_blank\">" + str4 + "</a><br/>联系电话：" + str5 + "</h4>");
                        builder.Append("<div class=\"pic\">");
                        builder.Append("<a href=\"/partner.aspx?id=" + str3 + "\" title=\"" + str4 + "\" target=\"_blank\"><img alt=\"" + str4 + "\" src=\"" + str6 + "\" width=\"200\" height=\"121\"></a>");
                        builder.Append("</div>");
                        builder.Append("<div class=\"info\">" + str7 + "</div>");
                        builder.Append("</li>");
                    }
                }
            }
            this.ltpartne.Text = builder.ToString();
            this.pager.RecordCount = num;
        }
    }

    private void initWebName()
    {
        Maticsoft.BLL.System system = new Maticsoft.BLL.System();
        string strWhere = "";
        DataSet list = system.GetList(strWhere);
        if (((list != null) && (list.Tables.Count > 0)) && (list.Tables[0].Rows.Count > 0))
        {
            if ((list.Tables[0].Rows[0]["abbreviation"] == null) || (list.Tables[0].Rows[0]["abbreviation"].ToString() == ""))
            {
                this.strWebName = "艾尚团购";
            }
            else
            {
                this.strWebName = list.Tables[0].Rows[0]["abbreviation"].ToString();
            }
        }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!this.Page.IsPostBack)
        {
            this.initNav();
            this.initWebName();
            this.initPage();
        }
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        this.initPage();
    }

}